<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wrr123.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="知识体系">
<meta property="og:type" content="article">
<meta property="og:title" content="java8特性详解">
<meta property="og:url" content="https://wrr123.github.io/2021/03/16/java8%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/index.html">
<meta property="og:site_name" content="一缕烟气">
<meta property="og:description" content="知识体系">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://localhost:4000/2021/03/16/java8%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/Java8.png">
<meta property="article:published_time" content="2021-03-16T01:28:26.000Z">
<meta property="article:modified_time" content="2022-02-18T02:52:04.437Z">
<meta property="article:author" content="田园隐士">
<meta property="article:tag" content="java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://localhost:4000/2021/03/16/java8%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/Java8.png">

<link rel="canonical" href="https://wrr123.github.io/2021/03/16/java8%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>java8特性详解 | 一缕烟气</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<style>mjx-container[jax="SVG"] {
  direction: ltr;
}

mjx-container[jax="SVG"] > svg {
  overflow: visible;
}

mjx-container[jax="SVG"][display="true"] {
  display: block;
  text-align: center;
  margin: 1em 0;
}

mjx-container[jax="SVG"][justify="left"] {
  text-align: left;
}

mjx-container[jax="SVG"][justify="right"] {
  text-align: right;
}

g[data-mml-node="merror"] > g {
  fill: red;
  stroke: red;
}

g[data-mml-node="merror"] > rect[data-background] {
  fill: yellow;
  stroke: none;
}

g[data-mml-node="mtable"] > line[data-line] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > rect[data-frame] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > .mjx-dashed {
  stroke-dasharray: 140;
}

g[data-mml-node="mtable"] > .mjx-dotted {
  stroke-linecap: round;
  stroke-dasharray: 0,140;
}

g[data-mml-node="mtable"] > svg {
  overflow: visible;
}

[jax="SVG"] mjx-tool {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;
}

[jax="SVG"] mjx-tool > mjx-tip {
  position: absolute;
  top: 0;
  left: 0;
}

mjx-tool > mjx-tip {
  display: inline-block;
  padding: .2em;
  border: 1px solid #888;
  font-size: 70%;
  background-color: #F8F8F8;
  color: black;
  box-shadow: 2px 2px 5px #AAAAAA;
}

g[data-mml-node="maction"][data-toggle] {
  cursor: pointer;
}

mjx-status {
  display: block;
  position: fixed;
  left: 1em;
  bottom: 1em;
  min-width: 25%;
  padding: .2em .4em;
  border: 1px solid #888;
  font-size: 90%;
  background-color: #F8F8F8;
  color: black;
}

foreignObject[data-mjx-xml] {
  font-family: initial;
  line-height: normal;
  overflow: visible;
}

.MathJax path {
  stroke-width: 3;
}

mjx-container[display="true"] {
  overflow: auto hidden;
}

mjx-container[display="true"] + br {
  display: none;
}
</style><link rel="alternate" href="/atom.xml" title="一缕烟气" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一缕烟气</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">沧海月明珠有泪，蓝田日暖玉生烟</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/16/java8%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          java8特性详解
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-16 09:28:26" itemprop="dateCreated datePublished" datetime="2021-03-16T09:28:26+08:00">2021-03-16</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>6.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>6 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h4 id="知识体系"><a href="#知识体系" class="headerlink" title="知识体系"></a>知识体系</h4><p><img src="http://localhost:4000/2021/03/16/java8%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/Java8.png" alt></p>
<span id="more"></span>
<h4 id="函数编程（Lambda表达式）"><a href="#函数编程（Lambda表达式）" class="headerlink" title="函数编程（Lambda表达式）"></a>函数编程（Lambda表达式）</h4><p>面向对象编程是对数据进行抽象；<strong>函数式编程是对行为进行抽象。</strong></p>
<p>核心思想：</p>
<ul>
<li>使用不可变值和函数，函数对一个值进行处理，映射成另一个值。</li>
</ul>
<h5 id="Lambda表达式"><a href="#Lambda表达式" class="headerlink" title="Lambda表达式"></a>Lambda表达式</h5><p>lambda表达式仅能放入 <strong>预定义使用了@Functional注解的函数式接口，自带一个抽象函数的方法，或者SAM（Single Abstract Method 单个抽象方法）类型。</strong></p>
<ul>
<li>Lambda内部可以使用静态、非静态和局部变量，这成为lambda内的变量捕获。</li>
<li>Lambda表达式在java中又可成为 <strong>闭包或匿名函数。</strong></li>
<li>Lambda表达式有个限制，那就是只能引用final或final局部变量，这就是说不能在lambda表达式内部修改定义在域外的变量。</li>
</ul>
<h5 id="分类"><a href="#分类" class="headerlink" title="分类"></a>分类</h5><ul>
<li>惰性求值方法</li>
<li>及早求值方法</li>
</ul>
<h5 id="stream-和-parallelStream"><a href="#stream-和-parallelStream" class="headerlink" title="stream 和 parallelStream"></a>stream 和 parallelStream</h5><p>每个stream都有两种模式：顺序执行和并行执行。</p>
<h5 id="Stream中常用的方法"><a href="#Stream中常用的方法" class="headerlink" title="Stream中常用的方法"></a>Stream中常用的方法</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">stream(), parallelStream()</span><br><span class="line">filter()</span><br><span class="line">findAny() findFirst()</span><br><span class="line">sort</span><br></pre></td></tr></table></figure>
<p><code>forEach</code> void</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">map(), reduce()</span><br></pre></td></tr></table></figure>
<p><code>flatMap()</code> - 将多个Stream连接成一个Stream</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">collect(Collectors.toList())</span><br><span class="line">distinct, limit</span><br><span class="line">count</span><br><span class="line">min, max, summaryStatistics</span><br></pre></td></tr></table></figure>
<h4 id="Optional类深度解析"><a href="#Optional类深度解析" class="headerlink" title="Optional类深度解析"></a>Optional类深度解析</h4><p>这是一个可以为null的容器对象。如果值存在则<code>isPresent()</code>方法会返回true，调用<code>get()</code>方法会返回该对象。</p>
<h5 id="Optional类包含的方法"><a href="#Optional类包含的方法" class="headerlink" title="Optional类包含的方法"></a>Optional类包含的方法</h5><ul>
<li><p><code>of</code> 为非null的值创建一个Optional。如果你传了一个null，则会报错<code>NullPointerException</code>。</p>
</li>
<li><p><code>ofNullable</code> 为指定的值创建一个Optional，如果指定的值为null，则返回一个空的Optional。</p>
</li>
<li><p><code>isPresent</code> 如果值存在，则返回true，否则返回false。</p>
</li>
<li><p><code>get</code> 如果Optional有值则将其返回，否则抛出<code>NoSuchElementException</code>。</p>
</li>
<li><p><code>ifPresent</code> 如果Optional实例有值，则为其调用<code>consumer</code>，否则不做处理。</p>
</li>
<li><p><code>orElse</code> 如果有值则将其返回，否则返回指定的其他值。</p>
</li>
<li><p><code>orElseGet</code> <code>orElseGet</code> 和 <code>orElse</code> 类似，区别在于得到的默认值。<code>orElse</code>将和optional中元素类型相同的值作为默认值，<code>orElseGet</code>方法可以接受<code>Supplier</code>接口的实现用来生成默认值。</p>
</li>
<li><p><code>orElseThrow</code> 如果有值将其返回，否则抛出<code>Supplier</code>接口创建的异常。</p>
</li>
<li><p><code>map</code> 如果有值，则对其执行调用mapping函数得到返回值。如果返回值不为null，则创建包含mapping返回值的Optional作为map方法返回值，否则返回空Optional。</p>
</li>
<li><p><code>flatMap</code> </p>
<blockquote>
<p>如果有值，为其执行mapping函数返回Optional类型返回值，否则返回空Optional。flatMap与map(Funtion)方法类似，区别在于flatMap中的mapper返回值必须是Optional。调用结束时，flatMap不会对结果用Optional封装。</p>
</blockquote>
</li>
<li><p><code>filter</code>  通过传入限定条件对Optional实例的值进行过滤。</p>
</li>
</ul>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">OptionalDemo</span> {</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">    <span class="comment">//创建Optional实例，也可以通过方法返回值得到。</span></span><br><span class="line">    Optional&lt;String&gt; name = Optional.of(<span class="string">"Sanaulla"</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//创建没有值的Optional实例，例如值为'null'</span></span><br><span class="line">    <span class="type">Optional</span> <span class="variable">empty</span> <span class="operator">=</span> Optional.ofNullable(<span class="literal">null</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//isPresent方法用来检查Optional实例是否有值。</span></span><br><span class="line">    <span class="keyword">if</span> (name.isPresent()) {</span><br><span class="line">      <span class="comment">//调用get()返回Optional值。</span></span><br><span class="line">      System.out.println(name.get());</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> {</span><br><span class="line">      <span class="comment">//在Optional实例上调用get()抛出NoSuchElementException。</span></span><br><span class="line">      System.out.println(empty.get());</span><br><span class="line">    } <span class="keyword">catch</span> (NoSuchElementException ex) {</span><br><span class="line">      System.out.println(ex.getMessage());</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">//ifPresent方法接受lambda表达式参数。</span></span><br><span class="line">    <span class="comment">//如果Optional值不为空，lambda表达式会处理并在其上执行操作。</span></span><br><span class="line">    name.ifPresent((value) -&gt; {</span><br><span class="line">      System.out.println(<span class="string">"The length of the value is: "</span> + value.length());</span><br><span class="line">    });</span><br><span class="line"></span><br><span class="line">    <span class="comment">//如果有值orElse方法会返回Optional实例，否则返回传入的错误信息。</span></span><br><span class="line">    System.out.println(empty.orElse(<span class="string">"There is no value present!"</span>));</span><br><span class="line">    System.out.println(name.orElse(<span class="string">"There is some value!"</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//orElseGet与orElse类似，区别在于传入的默认值。</span></span><br><span class="line">    <span class="comment">//orElseGet接受lambda表达式生成默认值。</span></span><br><span class="line">    System.out.println(empty.orElseGet(() -&gt; <span class="string">"Default Value"</span>));</span><br><span class="line">    System.out.println(name.orElseGet(() -&gt; <span class="string">"Default Value"</span>));</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> {</span><br><span class="line">      <span class="comment">//orElseThrow与orElse方法类似，区别在于返回值。</span></span><br><span class="line">      <span class="comment">//orElseThrow抛出由传入的lambda表达式/方法生成异常。</span></span><br><span class="line">      empty.orElseThrow(ValueAbsentException::<span class="keyword">new</span>);</span><br><span class="line">    } <span class="keyword">catch</span> (Throwable ex) {</span><br><span class="line">      System.out.println(ex.getMessage());</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">//map方法通过传入的lambda表达式修改Optonal实例默认值。 </span></span><br><span class="line">    <span class="comment">//lambda表达式返回值会包装为Optional实例。</span></span><br><span class="line">    Optional&lt;String&gt; upperName = name.map((value) -&gt; value.toUpperCase());</span><br><span class="line">    System.out.println(upperName.orElse(<span class="string">"No value found"</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//flatMap与map(Funtion)非常相似，区别在于lambda表达式的返回值。</span></span><br><span class="line">    <span class="comment">//map方法的lambda表达式返回值可以是任何类型，但是返回值会包装成Optional实例。</span></span><br><span class="line">    <span class="comment">//但是flatMap方法的lambda返回值总是Optional类型。</span></span><br><span class="line">    upperName = name.flatMap((value) -&gt; Optional.of(value.toUpperCase()));</span><br><span class="line">    System.out.println(upperName.orElse(<span class="string">"No value found"</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//filter方法检查Optiona值是否满足给定条件。</span></span><br><span class="line">    <span class="comment">//如果满足返回Optional实例值，否则返回空Optional。</span></span><br><span class="line">    Optional&lt;String&gt; longName = name.filter((value) -&gt; value.length() &gt; <span class="number">6</span>);</span><br><span class="line">    System.out.println(longName.orElse(<span class="string">"The name is less than 6 characters"</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//另一个示例，Optional值不满足给定条件。</span></span><br><span class="line">    Optional&lt;String&gt; anotherName = Optional.of(<span class="string">"Sana"</span>);</span><br><span class="line">    Optional&lt;String&gt; shortName = anotherName.filter((value) -&gt; value.length() &gt; <span class="number">6</span>);</span><br><span class="line">    System.out.println(shortName.orElse(<span class="string">"The name is less than 6 characters"</span>));</span><br><span class="line"></span><br><span class="line">  }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="默认方法"><a href="#默认方法" class="headerlink" title="默认方法"></a>默认方法</h4><h5 id="什么叫默认方法？"><a href="#什么叫默认方法？" class="headerlink" title="什么叫默认方法？"></a>什么叫默认方法？</h5><p>简单说，就是接口可以有实现方法，而且不需要实现类去实现其方法。只需在方法名前面加个<code>default</code>关键字即可。</p>
<h6 id="为什么会出现默认方法？"><a href="#为什么会出现默认方法？" class="headerlink" title="为什么会出现默认方法？"></a>为什么会出现默认方法？</h6><blockquote>
<p>为什么要有这个特性? 首先，之前的接口是个双刃剑，好处是面向抽象而不是面向具体编程，缺陷是，当需要修改接口时候，需要修改全部实现该接口的类，目前的java 8之前的集合框架没有foreach方法，通常能想到的解决办法是在JDK里给相关的接口添加新的方法及实现。然而，对于已经发布的版本，是没法在给接口添加新方法的同时不影响已有的实现。所以引进的默认方法。他们的目的是为了解决接口的修改与现有的实现不兼容的问题。</p>
</blockquote>
<h6 id="java8抽象类和接口的对比"><a href="#java8抽象类和接口的对比" class="headerlink" title="java8抽象类和接口的对比"></a>java8抽象类和接口的对比</h6><div class="table-container">
<table>
<thead>
<tr>
<th>相同点</th>
<th>不同点</th>
</tr>
</thead>
<tbody>
<tr>
<td>都是抽象类型</td>
<td>抽象类不可以多重继承，而接口可以（无论是多重类型继承还是多重行为继承）</td>
</tr>
<tr>
<td>都可以有实现方法（java8以前不行）</td>
<td>抽象类和接口所反映出的设计理念不同。抽象类表示的是<code>is-a</code>的关系，而接口表示的是<code>like-a</code>的关系</td>
</tr>
<tr>
<td>都可以不需要实现类或继承类去实现所有的方法</td>
<td>抽象类的变量默认是friendly型，其值可以在子类中重新定义，也可以重新赋值；接口中定义的变量默认是<code>public static final</code>型，且必须给其初值，所以实现类中不能改变其值</td>
</tr>
</tbody>
</table>
</div>
<h4 id="类型注解"><a href="#类型注解" class="headerlink" title="类型注解"></a>类型注解</h4><ul>
<li>在java8之前，注解只能是在声明的地方所使用，比如类、方法、属性；</li>
<li>java8里面，注解可以应用在任何地方。</li>
</ul>
<h5 id="类型注解的作用"><a href="#类型注解的作用" class="headerlink" title="类型注解的作用"></a>类型注解的作用</h5><p>类型注解被用来支持在Java的程序中做强制类型检查。配合插件式的<code>check framework</code>，可以在编译的时候检测出<code>runtime error</code>，以提高代码质量。这就是类型注解的作用了。</p>
<h4 id="重复注解"><a href="#重复注解" class="headerlink" title="重复注解"></a>重复注解</h4><h5 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h5><p>允许在同一申明类型（类、属性、方法）上，多次使用同一个注解。</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Repeatable(Authorities.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Authority {</span><br><span class="line">     String <span class="title function_">role</span><span class="params">()</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Authorities {</span><br><span class="line">    Authority[] value();</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RepeatAnnotationUseNewVersion</span> {</span><br><span class="line">    <span class="meta">@Authority(role="Admin")</span></span><br><span class="line">    <span class="meta">@Authority(role="Manager")</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">doSomeThing</span><span class="params">()</span>{ }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="类型推断优化"><a href="#类型推断优化" class="headerlink" title="类型推断优化"></a>类型推断优化</h4><h5 id="什么叫泛型？"><a href="#什么叫泛型？" class="headerlink" title="什么叫泛型？"></a>什么叫泛型？</h5><p>泛型的本质是参数化类型，也就是说所操作的数据类型被指定为一个参数。通俗点讲，就是“类型的变量”。这种类型变量可以用在类、接口和方法的创建中。</p>
<h5 id="java8的泛型类型推断改进"><a href="#java8的泛型类型推断改进" class="headerlink" title="java8的泛型类型推断改进"></a>java8的泛型类型推断改进</h5><ol>
<li>支持通过方法上下文推断泛型目标类型</li>
<li>支持在方法调用链路中，泛型类型推断传递到最后一个方法。</li>
</ol>
<h4 id="JRE精简"><a href="#JRE精简" class="headerlink" title="JRE精简"></a>JRE精简</h4><h5 id="JRE精简的好处"><a href="#JRE精简的好处" class="headerlink" title="JRE精简的好处"></a>JRE精简的好处</h5><ul>
<li>更小的Java环境需要更少的计算资源</li>
<li>一个较小的运行时环境可以更好的优化性能和启动时间</li>
<li>消除未使用的代码从安全的角度总是好的</li>
<li>这些打包的应用程序可以下载速度更快</li>
</ul>
<h5 id="jdeps工具使用"><a href="#jdeps工具使用" class="headerlink" title="jdeps工具使用"></a>jdeps工具使用</h5><h4 id="移除Permgen"><a href="#移除Permgen" class="headerlink" title="移除Permgen"></a>移除Permgen</h4><h5 id="Permgen-Space简单介绍"><a href="#Permgen-Space简单介绍" class="headerlink" title="Permgen Space简单介绍"></a>Permgen Space简单介绍</h5><p>PermGen Space的全称为<code>Permanent Generation Space</code>，是指内存的永久保存区域。</p>
<blockquote>
<p>说说为什么会内存益出: 这一部分用于存放Class和Meta的信息,Class在被 Load的时候被放入PermGen space区域，它和和存放Instance的Heap区域不同,所以如果你的APP会LOAD很多CLASS的话,就很可能出现PermGen space错误。这种错误常见在web服务器对JSP进行pre compile的时候。</p>
</blockquote>
<h4 id="StampedLock"><a href="#StampedLock" class="headerlink" title="StampedLock"></a>StampedLock</h4><h5 id="synchronized"><a href="#synchronized" class="headerlink" title="synchronized"></a>synchronized</h5><p>它是java语言的关键字，当它用来修饰一个方法或者一个代码块的时候，能够保证在同一时刻最多只有一个线程执行该段代码。</p>
<p>四种不同的同步块：</p>
<ol>
<li>实例方法</li>
<li>静态方法</li>
<li>实例方法的同步块</li>
<li>静态方法的同步块</li>
</ol>
<h5 id="Lock"><a href="#Lock" class="headerlink" title="Lock"></a>Lock</h5><h5 id="StampedLock-1"><a href="#StampedLock-1" class="headerlink" title="StampedLock"></a>StampedLock</h5><h4 id="LocalDate-LocalDateTime"><a href="#LocalDate-LocalDateTime" class="headerlink" title="LocalDate/LocalDateTime"></a>LocalDate/LocalDateTime</h4><h4 id="JavaFX"><a href="#JavaFX" class="headerlink" title="JavaFX"></a>JavaFX</h4><h4 id="其他更新"><a href="#其他更新" class="headerlink" title="其他更新"></a>其他更新</h4><h5 id="处理数值"><a href="#处理数值" class="headerlink" title="处理数值"></a>处理数值</h5><p>java8添加了严格的数学运算。</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> {</span><br><span class="line">    Math.addExact(Integer.MAX_VALUE, <span class="number">1</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">catch</span> (ArithmeticException e) {</span><br><span class="line">    System.err.println(e.getMessage());</span><br><span class="line">    <span class="comment">// =&gt; integer overflow</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="处理文件"><a href="#处理文件" class="headerlink" title="处理文件"></a>处理文件</h5><p>java8可以将文件用于函数式数据流。</p>
<p>一个栗子：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> (Stream&lt;Path&gt; stream = Files.list(Paths.get(<span class="string">""</span>))) {</span><br><span class="line">    <span class="type">String</span> <span class="variable">joined</span> <span class="operator">=</span> stream</span><br><span class="line">        .map(String::valueOf)</span><br><span class="line">        .filter(path -&gt; !path.startsWith(<span class="string">"."</span>))</span><br><span class="line">        .sorted()</span><br><span class="line">        .collect(Collectors.joining(<span class="string">"; "</span>));</span><br><span class="line">    System.out.println(<span class="string">"List: "</span> + joined);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h5 id="查找文件"><a href="#查找文件" class="headerlink" title="查找文件"></a>查找文件</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Path</span> <span class="variable">start</span> <span class="operator">=</span> Paths.get(<span class="string">""</span>);</span><br><span class="line"><span class="type">int</span> <span class="variable">maxDepth</span> <span class="operator">=</span> <span class="number">5</span>;</span><br><span class="line"><span class="keyword">try</span> (Stream&lt;Path&gt; stream = Files.find(start, maxDepth, (path, attr) -&gt;</span><br><span class="line">        String.valueOf(path).endsWith(<span class="string">".js"</span>))) {</span><br><span class="line">    <span class="type">String</span> <span class="variable">joined</span> <span class="operator">=</span> stream</span><br><span class="line">        .sorted()</span><br><span class="line">        .map(String::valueOf)</span><br><span class="line">        .collect(Collectors.joining(<span class="string">"; "</span>));</span><br><span class="line">    System.out.println(<span class="string">"Found: "</span> + joined);</span><br><span class="line">}</span><br><span class="line">  </span><br></pre></td></tr></table></figure>
<h5 id="读写文件"><a href="#读写文件" class="headerlink" title="读写文件"></a>读写文件</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> (Stream&lt;String&gt; stream = Files.lines(Paths.get(<span class="string">"res/nashorn1.js"</span>))) {</span><br><span class="line">    stream</span><br><span class="line">        .filter(line -&gt; line.contains(<span class="string">"print"</span>))</span><br><span class="line">        .map(String::trim)</span><br><span class="line">        .forEach(System.out::println);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/java/" rel="tag"># java</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/03/14/springboot-how2j/" rel="prev" title="springboot-how2j">
      <i class="fa fa-chevron-left"></i> springboot-how2j
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/03/17/springCloud-basis/" rel="next" title="springCloud-basis">
      springCloud-basis <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB"><span class="nav-number">1.</span> <span class="nav-text">知识体系</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%87%BD%E6%95%B0%E7%BC%96%E7%A8%8B%EF%BC%88Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%89"><span class="nav-number">2.</span> <span class="nav-text">函数编程（Lambda表达式）</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-number">2.1.</span> <span class="nav-text">Lambda表达式</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%88%86%E7%B1%BB"><span class="nav-number">2.2.</span> <span class="nav-text">分类</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#stream-%E5%92%8C-parallelStream"><span class="nav-number">2.3.</span> <span class="nav-text">stream 和 parallelStream</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Stream%E4%B8%AD%E5%B8%B8%E7%94%A8%E7%9A%84%E6%96%B9%E6%B3%95"><span class="nav-number">2.4.</span> <span class="nav-text">Stream中常用的方法</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Optional%E7%B1%BB%E6%B7%B1%E5%BA%A6%E8%A7%A3%E6%9E%90"><span class="nav-number">3.</span> <span class="nav-text">Optional类深度解析</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Optional%E7%B1%BB%E5%8C%85%E5%90%AB%E7%9A%84%E6%96%B9%E6%B3%95"><span class="nav-number">3.1.</span> <span class="nav-text">Optional类包含的方法</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%BB%98%E8%AE%A4%E6%96%B9%E6%B3%95"><span class="nav-number">4.</span> <span class="nav-text">默认方法</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E5%8F%AB%E9%BB%98%E8%AE%A4%E6%96%B9%E6%B3%95%EF%BC%9F"><span class="nav-number">4.1.</span> <span class="nav-text">什么叫默认方法？</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BC%9A%E5%87%BA%E7%8E%B0%E9%BB%98%E8%AE%A4%E6%96%B9%E6%B3%95%EF%BC%9F"><span class="nav-number">4.1.1.</span> <span class="nav-text">为什么会出现默认方法？</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#java8%E6%8A%BD%E8%B1%A1%E7%B1%BB%E5%92%8C%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AF%B9%E6%AF%94"><span class="nav-number">4.1.2.</span> <span class="nav-text">java8抽象类和接口的对比</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%B1%BB%E5%9E%8B%E6%B3%A8%E8%A7%A3"><span class="nav-number">5.</span> <span class="nav-text">类型注解</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%B1%BB%E5%9E%8B%E6%B3%A8%E8%A7%A3%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="nav-number">5.1.</span> <span class="nav-text">类型注解的作用</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%87%8D%E5%A4%8D%E6%B3%A8%E8%A7%A3"><span class="nav-number">6.</span> <span class="nav-text">重复注解</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AE%9A%E4%B9%89"><span class="nav-number">6.1.</span> <span class="nav-text">定义</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%B1%BB%E5%9E%8B%E6%8E%A8%E6%96%AD%E4%BC%98%E5%8C%96"><span class="nav-number">7.</span> <span class="nav-text">类型推断优化</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E5%8F%AB%E6%B3%9B%E5%9E%8B%EF%BC%9F"><span class="nav-number">7.1.</span> <span class="nav-text">什么叫泛型？</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#java8%E7%9A%84%E6%B3%9B%E5%9E%8B%E7%B1%BB%E5%9E%8B%E6%8E%A8%E6%96%AD%E6%94%B9%E8%BF%9B"><span class="nav-number">7.2.</span> <span class="nav-text">java8的泛型类型推断改进</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JRE%E7%B2%BE%E7%AE%80"><span class="nav-number">8.</span> <span class="nav-text">JRE精简</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#JRE%E7%B2%BE%E7%AE%80%E7%9A%84%E5%A5%BD%E5%A4%84"><span class="nav-number">8.1.</span> <span class="nav-text">JRE精简的好处</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#jdeps%E5%B7%A5%E5%85%B7%E4%BD%BF%E7%94%A8"><span class="nav-number">8.2.</span> <span class="nav-text">jdeps工具使用</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%A7%BB%E9%99%A4Permgen"><span class="nav-number">9.</span> <span class="nav-text">移除Permgen</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Permgen-Space%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D"><span class="nav-number">9.1.</span> <span class="nav-text">Permgen Space简单介绍</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#StampedLock"><span class="nav-number">10.</span> <span class="nav-text">StampedLock</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#synchronized"><span class="nav-number">10.1.</span> <span class="nav-text">synchronized</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Lock"><span class="nav-number">10.2.</span> <span class="nav-text">Lock</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#StampedLock-1"><span class="nav-number">10.3.</span> <span class="nav-text">StampedLock</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#LocalDate-LocalDateTime"><span class="nav-number">11.</span> <span class="nav-text">LocalDate&#x2F;LocalDateTime</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JavaFX"><span class="nav-number">12.</span> <span class="nav-text">JavaFX</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%85%B6%E4%BB%96%E6%9B%B4%E6%96%B0"><span class="nav-number">13.</span> <span class="nav-text">其他更新</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%A4%84%E7%90%86%E6%95%B0%E5%80%BC"><span class="nav-number">13.1.</span> <span class="nav-text">处理数值</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%A4%84%E7%90%86%E6%96%87%E4%BB%B6"><span class="nav-number">13.2.</span> <span class="nav-text">处理文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%9F%A5%E6%89%BE%E6%96%87%E4%BB%B6"><span class="nav-number">13.3.</span> <span class="nav-text">查找文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E8%AF%BB%E5%86%99%E6%96%87%E4%BB%B6"><span class="nav-number">13.4.</span> <span class="nav-text">读写文件</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">田园隐士</p>
  <div class="site-description" itemprop="description">talk is cheap, show me the code</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">347</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">田园隐士</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">587k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">8:53</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
          load: ['[tex]/mhchem'],
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
          packages: {'[+]': ['mhchem']},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

</body>
</html>
